package com.example.beikeyigou.dialog;

import android.app.Dialog;
import android.content.Context;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;

import androidx.annotation.NonNull;

import com.example.beikeyigou.R;

public class ChangHeadDialog extends Dialog {
    LinearLayout cameraBtn, localBtn;
    Button cancelBtn;

    public ChangHeadDialog(@NonNull Context context) {
        super(context);
        setContentView(R.layout.dialog_change_head);

        findView();
        setListener();
    }

    public interface OnChangeHeadListener {
        public void clickCamera();
        public void clickLocal();
    }
    OnChangeHeadListener onChangeHeadListener;

    public ChangHeadDialog setOnChangeHeadListener (OnChangeHeadListener onChangeHeadListener) {
        this.onChangeHeadListener = onChangeHeadListener;
        return this;
    }

    View.OnClickListener listener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            switch (v.getId()) {
                case R.id.dialog_change_head_camera:
                    if (onChangeHeadListener != null) {
                        onChangeHeadListener.clickCamera();
                    }
                    break;
                case R.id.dialog_change_head_photos:
                    if (onChangeHeadListener != null) {
                        onChangeHeadListener.clickLocal();
                    }
                    break;
            }
        }
    };

    private void setListener() {
        cameraBtn.setOnClickListener(listener);
        localBtn.setOnClickListener(listener);
        cancelBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });
    }

    private void findView() {
        cameraBtn = findViewById(R.id.dialog_change_head_camera);
        localBtn = findViewById(R.id.dialog_change_head_photos);
        cancelBtn = findViewById(R.id.dialog_change_head_cancel);
    }


}
